<?php
/**
 * Created by PhpStorm.
 * User: dx
 * Date: 17/3/6
 * Time: 下午15:03
 */
class AhpBasePage extends Eloquent
{
    protected $table = "ahp_base_page";

    public function ahp_users(){
        return $this->hasOne('AhpUsers',"id","created_by");
    }
    /**
     * @Author:      kc
     * @DateTime:    2017-03-07 10:07:10
     * @Description: 页面架构列表
     * @Param: $number 页面编号
     * @Param: $name 页面名称
     * @Param: $start_time 开始时间
     * @param: $end_time 结束时间
     * @param: $page 第几页
     * @param: $page_size 每页多少条
     * @Return: Object
     */
    public static function getBasePage($number=null,$name=null,$start_time=null,$end_time=null,$status,$page,$page_size){
        $ahp_page = AhpBasePage::where('status','!=',0)->orderBy('id','desc');
        if(!empty($number)){
            $ahp_page->where('pg_number','like','%'.$number.'%');
        }
        if(!empty($name)){
            $ahp_page->where('pg_name','like','%'.$name.'%');
        }
        if(!empty($start_time) && !empty($end_time)){
            $ahp_page->whereBetween('created_at',[$start_time.' 00:00:00',$end_time.' 23:59:59']);
        }
        if(Input::get('status')){
            $ahp_page->where('status',Input::get('status'));
        }
        $count = $ahp_page->count();
        $data = $ahp_page->skip($page_size*($page-1))->take($page_size)->get();
        foreach($data as $v){
            $v->module_num = AhpPgModRelation::where('pg_id',$v->id)->count();
            $v->created_by = AhpUsers::where('id',$v->created_by)->pluck('user_name');
        }
        $result = array(
            'count' => $count,
            'data' => $data,
        );
        return $result;
    }
}